<?php
/**
 * 充值消费送
 * 活动时间： 2015-6-1,2014-6-7
 */
date_default_timezone_set('Asia/Shanghai');

class IndexControl extends Control{
    private $model;
    private $uin;
    private $zoneid;
    private $uin_new;
    private $zoneid_new;
    private $s_time     = '2017-2-8 00:00:00';
    private $e_time     = '2017-3-31 23:59:59';
    private $channelid  = 0x09020001;     // 活动扣点 渠道规则 以 0x0902 开头   不可用于后台资产操作
    private $tableArr   = array();
    private $prizeTable = array(
        1  => array(
            'id'          => '1',
            'prizeName'   => '鲜花',
            'prizeIdBoy'  => '21250013',
            'prizeIdGirl' => '21250013',
            'useMethod'   => '2',
            'prizeType'   => '1',
            'quantity'    => '1000000'
        ),
        2  => array(
            'id'          => '2',
            'prizeName'   => '鲜花',
            'prizeIdBoy'  => '21250013',
            'prizeIdGirl' => '21250013',
            'useMethod'   => '2',
            'prizeType'   => '1',
            'quantity'    => '900000'
        ),
        3  => array(
            'id'          => '3',
            'prizeName'   => '鲜花',
            'prizeIdBoy'  => '21250013',
            'prizeIdGirl' => '21250013',
            'useMethod'   => '2',
            'prizeType'   => '1',
            'quantity'    => '800000'
        ),
        4  => array(
            'id'          => '4',
            'prizeName'   => '鲜花',
            'prizeIdBoy'  => '21250013',
            'prizeIdGirl' => '21250013',
            'useMethod'   => '2',
            'prizeType'   => '1',
            'quantity'    => '700000'
        ),
        5  => array(
            'id'          => '5',
            'prizeName'   => '鲜花',
            'prizeIdBoy'  => '21250013',
            'prizeIdGirl' => '21250013',
            'useMethod'   => '2',
            'prizeType'   => '1',
            'quantity'    => '600000'
        ),
        6  => array(
            'id'          => '6',
            'prizeName'   => '鲜花',
            'prizeIdBoy'  => '21250013',
            'prizeIdGirl' => '21250013',
            'useMethod'   => '2',
            'prizeType'   => '1',
            'quantity'    => '500000'
        ),
        7  => array(
            'id'          => '7',
            'prizeName'   => '鲜花',
            'prizeIdBoy'  => '21250013',
            'prizeIdGirl' => '21250013',
            'useMethod'   => '2',
            'prizeType'   => '1',
            'quantity'    => '400000'
        ),
        8  => array(
            'id'          => '8',
            'prizeName'   => '鲜花',
            'prizeIdBoy'  => '21250013',
            'prizeIdGirl' => '21250013',
            'useMethod'   => '2',
            'prizeType'   => '1',
            'quantity'    => '300000'
        ),
        9  => array(
            'id'          => '9',
            'prizeName'   => '鲜花',
            'prizeIdBoy'  => '21250013',
            'prizeIdGirl' => '21250013',
            'useMethod'   => '2',
            'prizeType'   => '1',
            'quantity'    => '250000'
        ),
        10 => array(
            'id'          => '10',
            'prizeName'   => '鲜花',
            'prizeIdBoy'  => '21250013',
            'prizeIdGirl' => '21250013',
            'useMethod'   => '2',
            'prizeType'   => '1',
            'quantity'    => '200000'
        ),
        11 => array(
            'id'          => '11',
            'prizeName'   => '樱花香气',
            'prizeIdBoy'  => '25650002',
            'prizeIdGirl' => '25650002',
            'useMethod'   => '1',
            'prizeType'   => '1',
            'quantity'    => '2147483647'
        ),
        12 => array(
            'id'          => '12',
            'prizeName'   => '樱花香气',
            'prizeIdBoy'  => '25650002',
            'prizeIdGirl' => '25650002',
            'useMethod'   => '1',
            'prizeType'   => '1',
            'quantity'    => '2147483647'
        ),
        13 => array(
            'id'          => '13',
            'prizeName'   => '樱花香气',
            'prizeIdBoy'  => '25650002',
            'prizeIdGirl' => '25650002',
            'useMethod'   => '1',
            'prizeType'   => '1',
            'quantity'    => '2147483647'
        ),
        14 => array(
            'id'          => '14',
            'prizeName'   => '樱花香气',
            'prizeIdBoy'  => '25650002',
            'prizeIdGirl' => '25650002',
            'useMethod'   => '1',
            'prizeType'   => '1',
            'quantity'    => '7776000'
        ),
        15 => array(
            'id'          => '15',
            'prizeName'   => '樱花香气',
            'prizeIdBoy'  => '25650002',
            'prizeIdGirl' => '25650002',
            'useMethod'   => '1',
            'prizeType'   => '1',
            'quantity'    => '7776000'
        ),
        16 => array(
            'id'          => '16',
            'prizeName'   => '樱花香气',
            'prizeIdBoy'  => '25650002',
            'prizeIdGirl' => '25650002',
            'useMethod'   => '1',
            'prizeType'   => '1',
            'quantity'    => '5184000'
        ),
        17 => array(
            'id'          => '17',
            'prizeName'   => '樱花香气',
            'prizeIdBoy'  => '25650002',
            'prizeIdGirl' => '25650002',
            'useMethod'   => '1',
            'prizeType'   => '1',
            'quantity'    => '5184000'
        ),
        18 => array(
            'id'          => '18',
            'prizeName'   => '樱花香气',
            'prizeIdBoy'  => '25650002',
            'prizeIdGirl' => '25650002',
            'useMethod'   => '1',
            'prizeType'   => '1',
            'quantity'    => '5184000'
        ),
        19 => array(
            'id'          => '19',
            'prizeName'   => '樱花香气',
            'prizeIdBoy'  => '25650002',
            'prizeIdGirl' => '25650002',
            'useMethod'   => '1',
            'prizeType'   => '1',
            'quantity'    => '2592000'
        ),
        20 => array(
            'id'          => '20',
            'prizeName'   => '樱花香气',
            'prizeIdBoy'  => '25650002',
            'prizeIdGirl' => '25650002',
            'useMethod'   => '1',
            'prizeType'   => '1',
            'quantity'    => '2592000'
        )
    );

    //构造函数
    function __construct(){
        parent::__construct();
        $this->actName = '女生节';

        $this->tableArr = array(
            'user_info'     => 'nsj_user_info',
            'sendPrize_log' => 'nsj_sendPrize_log',
            'prize_status'  => 'nsj_prize_status'
        );
        load_config('commonMain/onload');
        load_model('2017/main2017');   //公用的main.mod
        $this->model = new Main2017Model();

        //重新设置活动时间（用于外网、预发布环境）
        if(file_exists(APPLICATION_ROOT . '/config/basic.cfg.php')){
            //include文件的路径，$BasicCFG就存下了.php return 的数组
            $BasicCFG = include_once APPLICATION_ROOT . '/config/basic.cfg.php';
            if(!empty($BasicCFG[YEAR][ACT]['s_time']) && !empty($BasicCFG[YEAR][ACT]['e_time']) && $BasicCFG[YEAR][ACT]['price']){
                $this->s_time = $BasicCFG[YEAR][ACT]['s_time'];
                $this->e_time = $BasicCFG[YEAR][ACT]['e_time'];
                $this->price  = $BasicCFG[YEAR][ACT]['price'];
            }
        }
    }

    //析构函数
    function __destruct(){
    }

    /**
     * 页面入口
     */
    public function index(){
        $view          = array();
        $view['rank']  = $this->getRank();
        $view['isGet'] = 1;
        if(!$this->isLogin()){
            $userInfo         = $this->model->getGameUserInfo($this->uin, $this->zoneid);
            $zones            = get_dmz_game_zone();
            $view['RoleName'] = $userInfo['RoleName'];
            $view['ZoneID']   = $zones[$_SESSION[DOMAIN_ACT_ZONEID_KEY]];
            $view['money']    = $userInfo['Money'];
            if($userInfo['Gender'] == 2){ //女生
                $view['oneRank']  = $this->getOneRank();
                $view['oneCount'] = $this->getOneCount();
                if($view['oneCount'] == 0){
                    $view['oneRank'] = 0;
                }
                $view['isGet'] = $this->isGet();
            }else{
                $view['oneRank']  = 0;
                $view['oneCount'] = 0;
            }
        }
        load_view(ACT_PATH . '/index', $view);
    }

    private function getRank(){
        $userInfos = $this->model->getRows($this->tableArr['user_info'], "where roleSex=2  order by flowers desc  limit 100", "roleName,zoneId,flowers");
        $zones     = get_dmz_game_zone();
        $str       = '';
        $str .= '<tr height="31"><td width="74">排名</td><td width="116">昵称</td><td width="128">大区</td><td width="78">鲜花数</td></tr>';
        if(!empty($userInfos)){
            foreach($userInfos as $key => $value){
                $key++;
                if($value['flowers'] != 0){
                    if($key % 2 == 1){
                        $str .= '<tr style="color: rgb(202, 32, 221);">';
                    }else{
                        $str .= '<tr >';
                    }
                    $str .= '<td>' . $key . '</td><td>' . $value['roleName'] . '</td><td>' . $zones[$value['zoneId']] . '</td><td>' . $value['flowers'] . '</td>';
                }
            }
        }
        return $str;
    }

    private function isGet(){
        if(time() < strtotime('2017-04-01 00:00:00') || time() > strtotime('2017-04-07 23:59:59')){
            return 1;
        }else{
            $rank = $this->getOneRank();
            if($rank > 10 || $rank < 1){
                return 1;
            }else{
                $count = (int) $this->model->getValue($this->tableArr['prize_status'], "where prizeId={$rank}", 'count(*)');
                if($count > 0){
                    return 3;
                }else{
                    return 2;
                }
            }
        }
    }

    public function returnRank(){
        $key = isset($_POST['key']) ? urldecode($_POST['key']) : '';
        if(!empty($key)){
            $userInfos = $this->model->getRows($this->tableArr['user_info'], "where roleName like'%" . $key . "%' and roleSex=2  order by flowers desc  limit 100", "uin,roleName,zoneId,flowers");
        }else{
            $userInfos = $this->model->getRows($this->tableArr['user_info'], "where roleSex=2  order by flowers desc  limit 100", "uin,roleName,zoneId,flowers");
        }
        $zones = get_dmz_game_zone();
        $str   = '';
        $str .= '<tr height="31"><td width="74">排名</td><td width="116">昵称</td><td width="128">大区</td><td width="78">鲜花数</td></tr>';
        if(!empty($userInfos)){
            foreach($userInfos as $key => $value){
                $key++;
                if($value['flowers'] != 0){
                    $r = $this->getOneRank1($value['uin'], $value['zoneId']);
                    if($key % 2 == 1){
                        $str .= '<tr style="color: rgb(202, 32, 221);">';
                    }else{
                        $str .= '<tr >';
                    }
                    $str .= '<td>' . $r . ' </td><td>' . $value['roleName'] . '</td><td>' . $zones[$value['zoneId']] . '</td><td>' . $value['flowers'] . '</td>';
                }
            }
        }
        $data['rank'] = $str;
        echo json_encode($data);
    }

    //获取个人鲜花排名
    private function getOneRank(){
        $count = (int) $this->model->getValue($this->tableArr['user_info'], "where uin='{$_SESSION['UIN']}' and zoneId='{$_SESSION[DOMAIN_ACT_ZONEID_KEY]}'", 'flowers');
        $rank  = (int) $this->model->getValue($this->tableArr['user_info'], "where roleSex=2 and flowers>" . $count, 'count(*)');
        return $rank + 1;
    }

    //获取个人排名
    private function getOneRank1($uin, $zoneid){
        $count = (int) $this->model->getValue($this->tableArr['user_info'], "where uin='{$uin}' and zoneId='{$zoneid}'", 'flowers');
        $rank  = (int) $this->model->getValue($this->tableArr['user_info'], "where roleSex=2 and flowers>" . $count, 'count(*)');
        return $rank + 1;
    }

    //获取个人鲜花数
    private function getOneCount(){
        $count = (int) $this->model->getValue($this->tableArr['user_info'], "where uin='{$_SESSION['UIN']}' and zoneId='{$_SESSION[DOMAIN_ACT_ZONEID_KEY]}'", 'flowers');
        return $count;
    }

    public function getPrize(){
        if($this->isLogin()){
            exit(json_encode(array('code' => '001', 'msg' => '未登录')));
        }
        if(time() < strtotime('2017-04-01 00:00:00') || time() > strtotime('2017-04-07 23:59:59')){
            exit(json_encode(array('code' => '005', 'msg' => "亲,现在不是领取奖励的时间奥~~")));
        }
        $type = $this->getOneRank();
        if($type > 10 || $type < 1){
            exit(json_encode(array('code' => '005', 'msg' => "亲,你不能领取奖励噢~~")));
        }
        if($_SESSION['Gender'] == 1){
            exit(json_encode(array('code' => '005', 'msg' => "亲,你不能领取奖励噢~~")));
        }
        $counts = (int) $this->model->getValue($this->tableArr['sendPrize_log'], " ", 'count(*)');
        if($counts > 10){
            exit(json_encode(array('code' => '005', 'msg' => "亲,领取奖励出现错误请与客服联系~~")));
        }
        $counts = (int) $this->model->getValue($this->tableArr['sendPrize_log'], "where uin='{$_SESSION['UIN']}' and zoneId='{$_SESSION[DOMAIN_ACT_ZONEID_KEY]}'", 'count(*)');
        if($counts > 0){
            exit(json_encode(array('code' => '005', 'msg' => "亲,你已经领取过奖励了奥~~~")));
        }
        $count = (int) $this->model->getValue($this->tableArr['prize_status'], " where prizeId='{$type}'", 'count(*)');
        if($count > 0){
            exit(json_encode(array('code' => '005', 'msg' => "亲,你已经领取过奖励了奥~~")));
        }
        $sqlStatus = $this->model->insert_data($this->tableArr['prize_status'], array('prizeId' => $type));
        if(!$sqlStatus){
            exit(json_encode(array('code' => '005', 'msg' => "亲,请刷新页面后重试~~")));
        }
        $prize      = $this->prizeTable[$type];
        $quantity   = $prize['quantity'];
        $sendStatus = $this->send_userPrize($prize, $quantity);
        $awardSubID = 1;
        $logId      = $this->writeSendPrizeLog($prize, $awardSubID, $quantity, $sendStatus);

        $prize      = $this->prizeTable[$type + 10];
        $quantity   = $prize['quantity'];
        $sendStatus = $this->send_userPrize($prize, $quantity);
        $awardSubID = 1;
        $logId      = $this->writeSendPrizeLog($prize, $awardSubID, $quantity, $sendStatus);

        exit(json_encode(array('code' => '000', 'msg' => "亲,恭喜你领取奖励成功~~~")));
    }

    // 写发奖日志
    private function writeSendPrizeLog($prize, $awardSubID, $quantity, $sendStatus){
        $param = array(
            'uin'       => $_SESSION['UIN'],
            'zoneid'    => $_SESSION[DOMAIN_ACT_ZONEID_KEY],
            'roleName'  => $_SESSION['RoleName'],
            'account'   => $_SESSION['LoginUser'],
            'gender'    => $_SESSION['Gender'],
            'prizeType' => $prize['prizeType'],
            'prizeId'   => $prize['id'],
            'prizeName' => $prize['prizeName'],
            'quantity'  => $quantity,
            'useMethod' => $prize['useMethod'],
            'money'     => '0',
            'isAward'   => $awardSubID,
            'status'    => $sendStatus,
            'time'      => date('Y-m-d H:i:s')
        );
        return $this->model->insert_data($this->tableArr['sendPrize_log'], $param);
    }

    /**
     * 发物品_默认成功: 发一条奖品，可能会有套装，多个ID用|连接
     */
    private function send_userPrize($prize, $gain_id){
        $prizeID = $_SESSION['Gender'] == 1 ? $prize['prizeIdBoy'] : $prize['prizeIdGirl'];
        $data    = '';
        //发物品
        //0x10=游戏币，  0x08=代币
        if($prizeID == '0x10' || $prizeID == '0x08'){
            $send_user_prize = $this->model->sendGameItem($isAsset = 1, $this->uin, $this->zoneid, $prizeID, $prize['useMethod'], $gain_id, $prize['prizeName'], $actName = '新炫舞官方活动--桃花季签到');
            $data .= $send_user_prize;
        }else{
            $arr = explode('|', $prizeID);
            foreach($arr as $itemID){
                $send_user_prize = $this->model->sendGameItem($isAsset = 0, $this->uin, $this->zoneid, $itemID, $prize['useMethod'], $gain_id, $prize['prizeName'], $actName = '新炫舞官方活动--桃花季签到');
                $data .= $send_user_prize . ',';
            }
        }
        return $data;
    }

    /**
     * 登录判断
     */
    private function isLogin(){
        if(empty($_SESSION['UIN']) || empty($_SESSION[DOMAIN_ACT_ZONEID_KEY])){
            return true;
        }
        $this->uin        = $_SESSION['UIN'];
        $this->zoneid     = $_SESSION[DOMAIN_ACT_ZONEID_KEY];
        $ret              = ChangeUinByZone($_SESSION['UIN'], $_SESSION[DOMAIN_ACT_ZONEID_KEY]);
        $this->uin_new    = $ret['UIN'];
        $this->zoneid_new = $ret['ZoneID'];
        unset($ret);    //unset()销毁指定的变量
        return false;
    }

    /**
     * 活动时间判断
     */
    private function isActTime(){
        $curr_time = time();
        if($curr_time < strtotime($this->s_time)){
            $stime = date('Y年m月d日', strtotime($this->s_time));
            $etime = date('Y年m月d日', strtotime($this->e_time));
            $data  = array('code' => '002', 'msg' => '亲，活动暂未开始！<br />活动时间：' . $stime . '-' . $etime . '。');
            echo json_encode($data);
            exit(0);
        }else{
            if($curr_time > strtotime($this->e_time)){
                $data = array('code' => '002', 'msg' => '很抱歉,活动已经结束咯,亲，可以进入官网查看其他最新活动哦。');
                echo json_encode($data);
                exit(0);
            }
        }
    }

    /**
     * 登录处理
     */
    public function save(){
        load_library('pub:core/FOPassPort', false);
        if(array_key_exists('jumpto', $_GET)){
            $jumpto = urldecode(htmlspecialchars_decode(($_GET['jumpto'])));
        }else{
            $jumpto = DOMAIN_URL;
        }
        if(stripos($jumpto, 'xx5.com') === false){
            die('error');
        }
        $logouturl = 'http://passport.xx5.com/logout.php?gourl=' . urlencode(DOMAIN_URL);
        if(empty($_SESSION['UIN']) || empty($_SESSION['LoginUser'])){
            session_unset();
            dumpErrorCode('登录失败，请重试！', $logouturl);
        }
        //登录——邀请链接，url
        if(isset($_GET['getkey'])){
            $getkey             = trim($_GET['getkey']);
            $_SESSION['getkey'] = base64_decode($getkey);//解密后格式    uin-分区id
        }
        header("Location:" . $jumpto);
        exit();
    }

    /**
     * Enter description here ...
     * success=5会重新选择
     */
    function saveSelectZone(){
        if(!check_post_from()){
            echo json_encode(array('success' => 2, 'msg' => '选区出错~'));
            return;
        }

        $login = $this->isLogin(0);
        if($login == 0){
            //	echo json_encode(array('success'=>0,'msg'=>'请登录~'));
            return;
        }else{
            //$this->isLogin();
            $gamezone = isset($_POST['k']) ? intval($_POST['k']) : 0;

            $zone = get_dmz_game_zone();
            if(!array_key_exists($gamezone, $zone)){
                echo json_encode(array('success' => 2, 'msg' => '登录失败，请重试~'));
                return;
            }
            $_SESSION[DOMAIN_ACT_ZONEID_KEY] = $gamezone;
            $result                          = $this->model->getGameUserInfo($_SESSION['UIN'], $_SESSION[DOMAIN_ACT_ZONEID_KEY]);

            if(empty($result)){

                echo json_encode(array('success' => 2, 'msg' => '你选择分区未创建角色，请重新选择！'));
                return;
            }
            $_SESSION['RoleName'] = $result['RoleName'];
            $_SESSION['Gender']   = $result['Gender'];
            $_SESSION['Level']    = $result['Level'];
            $_SESSION['Money']    = $result['Money'];
            $_SESSION['IP']       = get_client_ip_from_ns(true);

            $this->uin        = $_SESSION['UIN'];
            $this->zoneid     = $_SESSION[DOMAIN_ACT_ZONEID_KEY];
            $ret              = ChangeUinByZone($_SESSION['UIN'], $_SESSION[DOMAIN_ACT_ZONEID_KEY]);
            $this->uin_new    = $ret['UIN'];
            $this->zoneid_new = $ret['ZoneID'];

            // 初始化用户信息
            $date   = date('Y-m-d H:i:s');
            $sql    = "INSERT INTO dmz_act_basic_2017.{$this->tableArr['user_info']} (uin,zoneid,roleSex,roleName,account,firstIp,lastIp,firstTime,lastTime)
					VALUES ({$_SESSION['UIN']},{$_SESSION[DOMAIN_ACT_ZONEID_KEY]},{$_SESSION['Gender']},'{$_SESSION['RoleName']}','{$_SESSION['LoginUser']}','{$_SESSION['IP']}','{$_SESSION['IP']}','{$date}','{$date}') 
                    ON DUPLICATE KEY UPDATE lastIP='{$_SESSION['IP']}',lastTime='{$date}';";
            $status = $this->model->query_sql($sql);
            echo json_encode(array('success' => 1, 'msg' => '成功！'));
        }
        return;
    }

    /**
     * 退出处理
     */
    public function logout(){
        session_unset();
        session_destroy();
        $gourl = empty($_GET['jumpto']) ? '' : $_GET['jumpto'];
        $gourl = empty($gourl) ? DOMAIN_URL : $gourl;
        $gourl = urlencode(htmlspecialchars_decode($gourl));
        header('Location: http://passport.xx5.com/logout.php?gourl=' . $gourl);
        flush();  //刷新输出缓冲
        exit();
    }

    /**
     * 同步账单中的送的鲜花次数到库中去    30分钟执行一次
     */
    public function updateFlower(){
        ini_set('memory_limit', '1024M');
        ini_set("max_execution_time", 800);
        $start_time = time();
        $cur_date   = date('Ymd');
        $userInfos  = $this->model->getRows("nsj_user_info", "where roleSex=2", "uin,zoneId,flowers");
        foreach($userInfos as $k => $v){
            $ret                     = ChangeUinByZone($v['uin'], $v['zoneId']);//大区转换
            $userInfos[$k]['uin']    = $ret['UIN'];
            $userInfos[$k]['zoneId'] = $ret['ZoneID'];
            //鲜花
            $intimate = (int) $this->model->getBillValue($cur_date, $ret['UIN'], $ret['ZoneID'], 9, 'value', 'bill');
            //入库当天鲜花
            $flower_count  = $intimate;
            $flower_curday = $this->model->getRow("nsj_flower", "where uin={$v['uin']} and zone_id={$v['zoneId']} and flower_day={$cur_date}", "flower_day,flower_count");
            $param         = array(
                'uin'          => (int) $v['uin'],
                'zone_id'      => (int) $v['zoneId'],
                'flower_day'   => (int) $cur_date,
                'flower_count' => $flower_count
            );
            if(empty($flower_curday)){
                $res = $this->model->insert_data("nsj_flower", $param);
            }else{
                $param = array(
                    'flower_count' => $flower_count
                );
                $res   = $this->model->update_data("nsj_flower", $param, "where uin={$v['uin']} and zone_id={$v['zoneId']} and flower_day={$cur_date}");
            }
            //计算总的鲜花
            $vote = $this->model->getRow("nsj_flower", "where uin={$v['uin']} and zone_id={$v['zoneId']}", "sum(flower_count) as flower");
            $vote = $vote['flower'];
            //入库
            $param = array(
                'flowers' => $vote
            );
            $res   = $this->model->update_data("nsj_user_info", $param, "where uin={$v['uin']} and zoneId={$v['zoneId']}");
        }
        $time     = date('Y-m-d H:i:s', time());
        $end_time = time();
        $D_value  = $end_time - $start_time;
        echo $time . "鲜花脚本时间间隔" . $D_value . "\n";
    }

    /**
     * 同步账单中的送的鲜花次数到库中去    23:55:00执行一次
     */
    public function updateFlower1(){
        ini_set('memory_limit', '1024M');
        ini_set("max_execution_time", 800);
        $start_time = time();
        $cur_date   = date('Ymd');
        $userInfos  = $this->model->getRows("nsj_user_info", "where roleSex=2", "uin,zoneId,flowers");
        foreach($userInfos as $k => $v){
            $ret                     = ChangeUinByZone($v['uin'], $v['zoneId']);//大区转换
            $userInfos[$k]['uin']    = $ret['UIN'];
            $userInfos[$k]['zoneId'] = $ret['ZoneID'];
            //鲜花
            $intimate = (int) $this->model->getBillValue($cur_date, $ret['UIN'], $ret['ZoneID'], 9, 'value', 'bill');
            //入库当天鲜花
            $flower_count  = $intimate;
            $flower_curday = $this->model->getRow("nsj_flower", "where uin={$v['uin']} and zone_id={$v['zoneId']} and flower_day={$cur_date}", "flower_day,flower_count");
            $param         = array(
                'uin'          => (int) $v['uin'],
                'zone_id'      => (int) $v['zoneId'],
                'flower_day'   => (int) $cur_date,
                'flower_count' => $flower_count
            );
            if(empty($flower_curday)){
                $res = $this->model->insert_data("nsj_flower", $param);
            }else{
                $param = array(
                    'flower_count' => $flower_count
                );
                $res   = $this->model->update_data("nsj_flower", $param, "where uin={$v['uin']} and zone_id={$v['zoneId']} and flower_day={$cur_date}");
            }
            //计算总的鲜花
            $vote = $this->model->getRow("nsj_flower", "where uin={$v['uin']} and zone_id={$v['zoneId']}", "sum(flower_count) as flower");
            $vote = $vote['flower'];
            //入库
            $param = array(
                'flowers' => $vote
            );
            $res   = $this->model->update_data("nsj_user_info", $param, "where uin={$v['uin']} and zoneId={$v['zoneId']}");
        }
        $time     = date('Y-m-d H:i:s', time());
        $end_time = time();
        $D_value  = $end_time - $start_time;
        echo $time . "每天晚上23点55分执行一次统计线上时间间隔" . $D_value . "\n";
    }
}
